<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>6_2_2-Props只读性质</title>
</head>

<body>


  <script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
  <div id="Application">
    <comp1 :count="7"></comp1>
    没有效果
  </div>
  <script>
    const App = Vue.createApp({});
    const comp1 = {
      props: {
        count: {
          //自定义验证，count值大于10
          validator: function (value) {
            if (typeof value != "number" || value <= 10) {
              return false;
            }
            return true;
          },
        },
      },
      data() {
        return {
          thisCount: this.count,
        };
      },
      methods: {
        click() {
          this.thisCount += 1;
        },
      },

      template: `
        <button @click="click">点击</button>
        <div>计数：{{thisCount}}</div>
        `,
    };
    App.component("comp1", comp1);
    App.mount("#Application");
  </script>
</body>

</html>